const path = require('path');
const fs = require('fs');
const { Sequelize } = require('sequelize');

const sequelize = new Sequelize({
    dialect: 'mariadb',
    dialectOptions: {
        charset: 'utf8mb4',
        collate: 'utf8mb4_unicode_ci',
        supportBigNumbers: true,
        bigNumberStrings: true
    },
    database: 'mall',
    username: 'root',
    password: 'Lzp785630',
    pool: {
        max: 5,
        min: 0,
        idle: 30000
    },
    timezone: '+08:00' //东八时区
});

sequelize.sync();

module.exports = sequelize;

// 引入所有Model
// const modelPath = path.resolve(__dirname, '../models');
// const files = fs.readdirSync(modelPath);
// const jsFiles = files.filter((f) => {
//     return f.endsWith('.js');
// });
// for (const f of jsFiles) {
//     require(path.resolve(modelPath, f));
// }
